package com.yxjwzpx.management.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.yxjwzpx.management.domain.MaintainCompany;
import com.yxjwzpx.management.service.IMaintainCompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 维保公司Controller
 * 
 * @author yxjwzpx
 * @date 2025-04-09
 */
@RestController
@RequestMapping("/management/company")
public class MaintainCompanyController extends BaseController
{
    @Autowired
    private IMaintainCompanyService maintainCompanyService;

    /**
     * 查询维保公司列表
     */
    @PreAuthorize("@ss.hasPermi('management:company:list')")
    @GetMapping("/list")
    public TableDataInfo list(MaintainCompany maintainCompany)
    {
        startPage();
        List<MaintainCompany> list = maintainCompanyService.selectMaintainCompanyList(maintainCompany);
        return getDataTable(list);
    }

    /**
     * 导出维保公司列表
     */
    @PreAuthorize("@ss.hasPermi('management:company:export')")
    @Log(title = "维保公司", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MaintainCompany maintainCompany)
    {
        List<MaintainCompany> list = maintainCompanyService.selectMaintainCompanyList(maintainCompany);
        ExcelUtil<MaintainCompany> util = new ExcelUtil<MaintainCompany>(MaintainCompany.class);
        util.exportExcel(response, list, "维保公司数据");
    }

    /**
     * 获取维保公司详细信息
     */
    @PreAuthorize("@ss.hasPermi('management:company:query')")
    @GetMapping(value = "/{companyId}")
    public AjaxResult getInfo(@PathVariable("companyId") Long companyId)
    {
        return success(maintainCompanyService.selectMaintainCompanyByCompanyId(companyId));
    }

    /**
     * 新增维保公司
     */
    @PreAuthorize("@ss.hasPermi('management:company:add')")
    @Log(title = "维保公司", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MaintainCompany maintainCompany)
    {
        return toAjax(maintainCompanyService.insertMaintainCompany(maintainCompany));
    }

    /**
     * 修改维保公司
     */
    @PreAuthorize("@ss.hasPermi('management:company:edit')")
    @Log(title = "维保公司", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MaintainCompany maintainCompany)
    {
        return toAjax(maintainCompanyService.updateMaintainCompany(maintainCompany));
    }

    /**
     * 删除维保公司
     */
    @PreAuthorize("@ss.hasPermi('management:company:remove')")
    @Log(title = "维保公司", businessType = BusinessType.DELETE)
	@DeleteMapping("/{companyIds}")
    public AjaxResult remove(@PathVariable Long[] companyIds)
    {
        return toAjax(maintainCompanyService.deleteMaintainCompanyByCompanyIds(companyIds));
    }
}
